package ace.tool.generate.code.impl.resolver.scheme.resolver.common;

import ace.tool.generate.code.impl.resolver.scheme.model.bo.sdk.SpringFactoriesInfo;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.Builder;
import lombok.RequiredArgsConstructor;
import org.apache.commons.text.StringSubstitutor;

/**
 * @author caspar
 * @date 2023/11/17 10:34
 */
@Builder
@RequiredArgsConstructor
public class SpringFactoriesInfoResolver {
  /**
   * ./ace-module-demo-projects/ace-module-demo-api
   */
  private final String projectRootDir;

  private final List<String> classFullNameImports;

  public SpringFactoriesInfo resolve() {

    return SpringFactoriesInfo.builder()
        .classFullNameImports(this.classFullNameImports)
        .fileFullName(this.getFileFullName())
        .build();
  }

  private String getFileFullName() {
    Map<String, String> data = new HashMap<>();
    data.put("projectRootDir", projectRootDir);
    return StringSubstitutor.replace(
        "${projectRootDir}/src/main/resources/META-INF/spring.factories", data);
  }
}
